<template>
	<scroll-view scroll-y="true" scroll-top="0" style="height:100vh;" :enable-back-to-top="true"
		@scrolltolower="scrolltolower">
		<view class="content">
			<!-- 搜索框 -->
			<view class="search-box-background">
				<view class="search-box">
					<!-- 地区选择 -->
					<view class="area-box" @click="areaClick()">
						<text class="area-text">{{whereCity}}市</text><uni-icons type="down" size="30"></uni-icons>
						<u-icon name="arrow-down" color="#000" size="18"></u-icon>
					</view>
					<u--input placeholder="请输入老师" prefixIcon="search" prefixIconStyle="font-size: 22px;color: #909399"
						shape="square" clearable @change="searchChange"></u--input>
				</view>
			</view>
			<!-- 间隔槽 -->
			<u-gap height="50" bgColor="#fff"></u-gap>
			<!-- 轮播图 -->
			<view class="swiper-box">
				<u-swiper :list="list1" @click="swiperClick()" :circular="true" bgColor="#fff" radius="10"
					:indicator="true" height="170"></u-swiper>
			</view>
			<!-- 通知 -->
			<view class="notice-box">
				<view class="notice-padding">
					<u--image :showLoading="true" src="/static/index/raiseVoice.png" width="50rpx"
						height="50rpx"></u--image>
					<text class="notice-text">通知</text>
					<text class="notice-textt" @click="noticeShow = true">{{notice}}</text>
				</view>
			</view>
			<!-- 学历分类 -->
			<scroll-view style="width: 100%;" scroll-x="true">
				<view class="education-box">
					<view class="education-item-box" v-for="(item,index) in educationData" :key="index"
						@click="educationClick(item,index)">
						<!-- 橘黄色 -->
						<view class="education-item">
							<text>{{item.dictLabel}}</text>
						</view class="education-item-txt">
						<text>{{item.dictLabel}}</text>
					</view>
				</view>
			</scroll-view>
			<!-- 科目 -->
			<view class="subject-box">
				<view class="subject-item-box" v-for="(item,index) in subjectData" :key="index"
					@click="subjectItemClick(index)">
					<text>{{item.dictLabel}}</text>
				</view>
			</view>
			<!-- 名师推荐 -->
			<view class="teacher-title-box">
				<text class="teacher-title-txt">名师推荐</text>
				<text class="teacher-title-more" @click="subjectItemClick()">更多>></text>
			</view>

			<view class="jh-h-100-min jh-w-p-100 jh-bg-white">
				<teacherList :teacherData="teacherData" @clickItem="clickItem"></teacherList>
			</view>

			<u-popup :show="noticeShow" @close="noticeShow = false" mode="center">
				<view class="jh-p-20 jh-w-500 ">
					<text>{{notice}}</text>
				</view>
			</u-popup>
		</view>
	</scroll-view>
</template>

<script>
	import teacherList from "components/teacherList/index.vue"
	import {
		rocTateList,
		noticeView,
		listDesk,
		listSubject,
		deskTutor
	} from "api/index/index.js"
	import {
		TutorNumber
	} from 'api/family/index.js'
	export default {
		data() {
			return {
				valueEducName: '',
				pageNum: 0,
				pageSize: 5,
				// 通知弹窗
				noticeShow: false,
				// 轮播数据
				list1: [],
				// 学历数据
				educationData: [],
				// 科目数据
				subjectData: [],
				// 科目数据index
				subjectDataIndex: 0,
				// 名师推荐列表
				teacherData: [],
				// 通知
				notice: "",
				// 查询的城市
				whereCity: '',
				// 总长度
				total: 0
			}
		},
		components: {
			teacherList
		},
		onShow() {
			// 获取选中的城市
			if (uni.getStorageSync('cityTxt')) {
				this.whereCity = uni.getStorageSync('cityTxt');
				// 推荐名师
				// this.deskTutorGet(uni.getStorageSync('cityTxt'))
			} else {
				uni.setStorageSync('cityTxt', '邢台');
			}
		},
		onLoad() {
			TutorNumber({}).then(res => {
				this.total = res
				deskTutor({
					teacherTeachingDtos: this.whereCity + '市',
					// pageNum: this.pageNum += 1,
					// pageSize: this.pageSize
				}).then(res => {
					this.teacherData = res.rows
				})

			})
			this.getList()
			this.scrolltolower()
		},
		methods: {
			// 滚动分页
			scrolltolower() {
				// let total = this.total / 3
				// if (Math.ceil(total) > this.pageNum) {
				deskTutor({
					educName: this.valueEducName,
					teacherTeachingDtos: this.whereCity + '市',
					// pageNum: this.pageNum += 1,
					// pageSize: this.pageSize
				}).then(res => {
					res.rows.forEach(el => {
						this.teacherData.push(el)
					})
				})
				// }

			},
			// 点击推荐教师
			clickItem(e) {
				let data = {
					teacherId: e.id,
					position: '首页'
				}
				uni.navigateTo({
					url: '/components/teacherDetails/teacherDetails?data=' + JSON.stringify(data)
				});
			},
			// 点击学历
			educationClick(item, index) {
				if (item.dictLabel == '更多') {
					uni.switchTab({
						url: '/pages/familyE/familyE'
					});
				} else {
					// 科目
					this.subjectDataIndex = index
					listSubject({
						fatherId: item.dictCode
					}).then(res => {
						this.subjectData = res.data
					})
				}

			},
			// get请求
			getList() {
				// 轮播
				rocTateList({}).then(res => {
					res.data.forEach(el => {
						this.list1.push('https://educationafter.jinghaischool.com' + el.pictures)
					})
				})
				// 通知
				noticeView({}).then(res => {
					this.notice = res.data.noticeTitle
				})
				// 学历
				listDesk().then(res => {
					this.educationData = res.data
					this.educationData.push({
						dictCode: 999999,
						dictLabel: "更多",
						dictValue: "999999"
					})
					console.log(this.educationData, 'this.educationData[0]');
					this.listSubjectGet(this.educationData[0].dictCode)
				})
			},
			// 科目选择
			subjectItemClick(e) {

				let educationDataValue = {
					fId: this.subjectDataIndex,
					childLevel: e
				}
				uni.reLaunch({
					url: `/pages/familyE/familyE?data=${JSON.stringify(educationDataValue)}`
				});
			},
			// 科目
			listSubjectGet(e) {
				listSubject({
					fatherId: e
				}).then(res => {
					this.subjectData = res.data
				})
			},
			// 名师推荐
			// deskTutorGet() {
			// 	deskTutor({
			// 		teacherTeachingDtos: this.whereCity + '市',
			// 		// pageNum: this.pageNum,
			// 		// pageSize: this.pageSize
			// 	}).then(res => {
			// 		this.teacherData = res.rows
			// 	})
			// },
			// 搜索
			searchChange(value) {
				this.valueEducName = value
				deskTutor({
					educName: value
				}).then(res => {
					this.teacherData = res.rows
				})
			},
			// 轮播图
			swiperClick(e) {
				if (e == 1) {
					uni.reLaunch({
						url: '/pages/checkInPlatform/checkInPlatform'
					});
				}
			},
			//地区切换
			areaClick() {
				uni.redirectTo({
					url: '/pages/index/areaPage/areaPage'
				});
			}
		}
	}
</script>

<style>
	.scroll-Y {
		min-height: 100vh;
	}

	.content {
		width: 100%;
		margin: auto;
		background-color: white;
		padding: 0 20rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.search-box-background {
		width: 100%;
		height: 75rpx;
		background-color: white;
		z-index: 1000000;
		position: fixed;
		top: -1rpx;
		display: flex;
		justify-content: center;
		padding: 10rpx 0;
	}

	.search-box {
		width: 94%;
		display: flex;
		line-height: 55rpx;


	}

	.area-box {
		display: flex;
	}

	.area-text {
		margin-right: 10rpx;
		margin-top: 5rpx;
	}

	::v-deep.u-input--radius.data-v-fdbb9fe6,
	.u-input--square.data-v-fdbb9fe6 {
		width: 70% !important;
		border-radius: 100rpx !important;
		margin-left: 20rpx;
	}

	.swiper-box {
		width: 100%;

	}

	::v-deep.u-swiper {
		box-shadow: 0rpx 0rpx 14rpx #353232;
	}

	.notice-box {
		width: 100%;
		height: 70rpx;
		background-color: #f0f0f0;
		border-radius: 15rpx;
		margin: 20rpx 0 0 0;
	}

	.notice-padding {
		padding: 10rpx 15rpx;
		display: flex;
		line-height: 50rpx;
	}

	.notice-text {
		font-size: 29rpx;
		font-weight: 600;
		margin: 0 15rpx 0 10rpx;
	}

	.notice-textt {
		width: 80.5%;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.education-box {
		height: 230rpx;
		margin-top: 30rpx;
		white-space: nowrap;
	}


	.education-item-box {
		text-align: center;
		width: 123rpx;
		min-height: 123rpx;
		margin: 0 25rpx 0 0;
		border-radius: 10000rpx;
		display: inline-block;
	}

	.education-item {
		width: 123rpx;
		height: 123rpx;
		margin: 0 25rpx 10rpx 0;
		border-radius: 10000rpx;
		background-color: #FF9600;
		text-align: center;
		line-height: 123rpx;
		color: white;
	}

	.subject-box {
		width: 100%;

		background-color: #04BC16;
		border-radius: 10rpx;
		display: flex;

		flex-wrap: wrap;
		padding: 1% 0;
	}

	.subject-item-box {
		height: 70rpx;
		/* width: 205rpx; */
		width: 28%;
		background-color: white;
		border-radius: 10rpx;
		text-align: center;
		display: flex;
		justify-content: center;
		align-items: center;
		margin: 2% 2.6%;
	}

	.teacher-title-box {
		width: 100%;
		margin: 20rpx 0 30rpx 0;
		display: flex;
		justify-content: space-between;
	}

	.teacher-title-txt {
		font-weight: 600;
		font-size: 30rpx;
	}

	.teacher-title-more {
		font-size: 27rpx;
		color: #625c5c;
	}
</style>